<template>
    <n-button type="primary" :disabled="!checkedRowKeys.length" @click="derived">
        导出实训
    </n-button>
    <!--展示实训-->
    <n-data-table
        :columns="columns"
        :data="admin.train"
        :bordered="false"
        :max-height="'75vh'"
        :scroll-x="1800"
        :row-key="rowKey"
        :checked-row-keys="checkedRowKeys"
        @update:checked-row-keys="handleCheck"
    />
</template>

<script setup>

import {useAdminStore} from "@/stores/admin";
import workApi from "@/http/workApi";

const admin = useAdminStore()

// 控制展示几种内容
const columns = [
    {
        type: 'selection'
    },
    {
        title: "实训名称",
        key: "name"
    },
    {
        title: "实训状态",
        key: "training_schedule"
    },
    {
        title: "实训班级",
        key: "training_class"
    },
    {
        title: "指导老师",
        key: "teacher"
    },
    {
        title: "创建时间",
        key: "time"
    },
    {
        title: "学生数量",
        key: "students_number"
    },
];

let rowKey = (row) => row.id
// 选中班级
let checkedRowKeys = ref([])
let handleCheck = (rowKeys) => {
    checkedRowKeys.value = rowKeys;
}
const derived = () =>{
    workApi.post('admin/training',{
        ids:[...checkedRowKeys.value]
    }).then((res)=>{
        window.open(res.url)
    })
}
</script>

<style scoped>

</style>